var httpc = require('http');
var network = require('network');
var net = network.openNetWorkClient();

var request_url = 'http://appengine.oss-cn-hangzhou.aliyuncs.com/httpTest.txt';

function http_get() {
  httpc.request({
    url: request_url,
    method: 'GET',
    timeout: 1000,
    headers: {
      'content-type': 'application/json',
    },
    success: function (data) {
      console.log('http: [debug] receive data is ' + data);
    }
  });
}

function http_post() {
  httpc.request({
    url: request_url,
    method: 'POST',
    timeout: 1000,
    headers: {
      'content-type': 'application/json',
    },
    success: function (data) {
      console.log('http: [debug] receive data is ' + data);
    }
  });
}

var netStu = net.getStatus();

if (netStu == 'connect') {
  http_get();
} else {
  net.on('connect', function() {
    http_get();
  })
}